<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" 
      xmlns:h="http://java.sun.com/jsf/html" 
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:p="http://primefaces.org/ui" xmlns:c="http://java.sun.com/jsp/jstl/core">
    <h:head>
        <title>Provisioning: Welcome!</title>
    </h:head>
    <h:body>
        <div style="text-align: center;">
            <h:panelGroup rendered="#{userSessionBean.loggedIn}" style="display:inline-block; width: 100%;">
                <p:panel header="Dashboard" style="width:800px; display:  inline-block;">
                    Welcome, #{userSessionBean.user.fullName}!
                    <h:form style="display: inline;"><h:commandButton value="Logout" action="#{userSessionBean.logOut()}"/></h:form>
                    <div>
                        <h:button outcome="make-order?faces-redirect=true" value="Make Order"/>
                        <h:button outcome="explorer?faces-redirect=true" value="Explore Network"/>
                        <h:button outcome="profile?faces-redirect=true" value="Manage Profile"/>
                    </div>
                </p:panel>
                <div><br/></div>
                <p:panel header="Your orders">
                    <h:form id="orders">
                        <p:dataTable var="order" id="orders" paginator="true" paginatorAlwaysVisible="false" rows="10" 
                                     paginatorTemplate="{CurrentPageReport}  {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}" 
                                     rowsPerPageTemplate="10,20,50" value="#{userSessionBean.user.orders()}">  
                            <p:column>  
                                <f:facet name="header">  
                                    Order ID  
                                </f:facet>  
                                <h:outputText value="#{order.id}" />  
                            </p:column>

                            <p:column>  
                                <f:facet name="header">  
                                    Order Date  
                                </f:facet>  
                                <h:outputText value="#{order.orderDate}" />  
                            </p:column>

                            <p:column>  
                                <f:facet name="header">  
                                    Router A / Router B 
                                </f:facet>  
                                <h:outputText value="#{order.sourceRouterName} / #{order.destinationRouterName}" style="font-size: 14px;" />  
                            </p:column>

                            <p:column>  
                                <f:facet name="header">  
                                    Status  
                                </f:facet>  
                                    <h:outputText style="color: green;" value="#{order.status}" rendered="#{order.status.equalsIgnoreCase('COMPLETED')}"/>
                                    <h:outputText style="color: blue;" value="#{order.status}" rendered="#{order.status.equalsIgnoreCase('PROCESSING')}"/>
                                    <h:outputText style="color: red;" value="#{order.status}" rendered="#{order.status.equalsIgnoreCase('FAIL')}"/>
                                    <h:outputText value="#{order.status}" rendered="#{order.status.equalsIgnoreCase('QUEUED')}"/>
                            </p:column>

                            <p:column>  
                                <f:facet name="header">  
                                    Actions  
                                </f:facet>
                                <h:commandLink value="Details" type="submit" action="#{orderDetailsBean.show(order)}"/>
                            </p:column>
                        </p:dataTable>
                        <p:poll autoStart="false" interval="10" update="orders" widgetVar="poll"/>
                        <h:selectBooleanCheckbox title="Auto refresh orders table" 
                                                 onclick="if(document.getElementById('orders:autoRefresh').checked)poll.start();else poll.stop();" id="autoRefresh"/> Auto refresh  
                    </h:form>
                </p:panel>
            </h:panelGroup>
            <h:panelGroup rendered="#{!userSessionBean.loggedIn}">
                You are not logged in. Please, <h:link outcome="index" value="login"/>.
            </h:panelGroup>
        </div>
    </h:body>
</html>
